<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch" data-options="{searchDatagrid:$.CurrentNavtab.find('#order-list-filter')}">
        <fieldset>
            <legend style="font-weight:normal;">页头搜索：</legend>
            <div style="margin:0; padding:1px 5px 5px;">
                <span>状态：</span>
                <input name="search_order_title" class="form-control" size="15" type="text">


                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">开始搜索！</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table class="table table-bordered" id="order-list-filter" data-toggle="datagrid" data-options="{
            height: '100%',
            gridTitle : '主工单列表',
            showToolbar: true,
            {{--toolbarItem: 'add,edit,del,|,import,export,exportf',--}}
            dataUrl: 'admin/order/getOrderListData?callback=?',
            dataType: 'jsonp',
            jsonPrefix: '',
            editMode: {dialog:{width:'800',height:500,title:'',mask:true}},
            editUrl: '../../html/datagrid/datagrid-edit.html?code={code}',
            paging: {pageSize:60},
            showCheckboxcol: true,
            linenumberAll: true,
            filterThead: false,
            importOption: {type:'dialog', options:{url:'../../html/datagrid/datagrid-import.html', width:500, height:300, title:'导入挂号信息'}},
            exportOption: {type:'file', options:{url:'http://b-jui.com/demo/export', loadingmask:true}}
        }">
        <thead>
        <tr>
            <th data-options="{name:'id',width:100}">工单ID</th>
            <th data-options="{name:'order_type'}">工单类型</th>
            <th data-options="{name:'order_title'}">工单号</th>
            <th data-options="{name:'contract_number'}">合同编号</th>
            <th data-options="{name:'customer_name'}">客户名称</th>
            <th data-options="{name:'product_name'}">产品名称</th>
            <th data-options="{name:'product_num'}">产品数量</th>
            <th data-options="{name:'create_user'}">下单人</th>
            <th data-options="{name:'create_time',align:'center',width:270}">创建时间</th>
            <th data-options="{name:'order_status',align:'center',render:orderStatus}">工单状态</th>
            <th data-options="{align:'center',width:270,render:orderDetail}">操作</th>

        </tr>
        </thead>
    </table>
</div>
<script>
    var curOrderId = '';

    function orderDetail(value, data) {
        var html = '<button type="button" class="btn btn-info" data-toggle="navtab" data-options="{id:\'permission_navtab\',fresh:true, url:\'/admin/order/getOrderProcessList\', title:\'工单工序列表\', data:{order_id:' + data.id + '}}"><i class="fa fa-sitemap"></i> 查看工单工序信息</button><br>';
        html += '<button type="button" class="btn btn-green" data-toggle="dialog" data-options="{id:\'order-detail-dialog\',fresh:true, url:\'/admin/order/getOrderDetail\', title:\'查看工单详情\',width:800,height:500, data:{order_id:' + data.id + '}}"><i class="fa fa-edit"></i> 查看主工单详情</button><br>';
//        html += '<button type="button" class="btn btn-yellow" data-toggle="navtab" data-options="{id:\'create_order_navtab\',fresh:true, url:\'/admin/order/copyOrder\', title:\'再来一单\', data:{copy_order_id:' + data.id + '}}"><i class="fa fa-copy"></i> 再来一单</button>';
        //html += '<button type="button" class="btn btn-info" data-toggle="dialog" data-options="{id:\'order-coursePrice-dialog\',fresh:true, url:\'/admin/order/coursePrice\',width:600,height:450, title:\'设置工资\', data:{order_id:' + data.id + '}}"></i> 设置工资</button>';
        return html
    }

    function orderStatus(value, data) {
        var html = '';
        if (data.status == 4) {//待派发状态
//            html = '<div>'+data.order_status+'</div>';
//            html = data.order_status + '<button onclick="getCurOrderId('+data.id+')" type="button" class="btn btn-info" data-toggle="alertmsg"  data-options="{type:\'confirm\', msg:\'确认派发？\',okCall:\'confirmAssign\'}"><i class="fa fa-sitemap"></i>派发</button>';
//            html = data.order_status + '<button  type="button" class="btn btn-info" data-toggle="dialog"  data-options="{id:\'order-assignment-dialog\',fresh:true,url:\'/admin/order/getOrderManageAssignmentType\',width:600,height:300, title:\'工单派发\', data:{order_id:' + data.id + '}}"><i class="fa fa-sitemap"></i>派发</button>';
            html = data.order_status + '<button  type="button" class="btn btn-info" onclick="confirmAssign('+data.id+')"><i class="fa fa-sitemap"></i>派发</button>';

        }else{
            html = '<div>'+data.order_status+'</div>';
        }

        html = '<div>'+data.order_status+'</div>';

        return html
    }

    function getCurOrderId(orderId){
        curOrderId = orderId;
    }

    function confirmAssign(order_id){
        BJUI.ajax('doajax', {
            url: '/admin/order/getOrderManageAssignmentType',
            data:{order_id:order_id},
            loadingmask: true,
            okCallback: function(json, options) {
                if(json.type == 1){//进入分派页面
                    BJUI.dialog({
                        id:'order-assignment-dialog',
                        url:'/admin/order/orderConfirmAssignmentBaseInfo',
                        data:{order_id:order_id},
                        title:'工单派发',
                        fresh:true,
                        width:600,
                        height:300
                    })
                }else if(json.type == 3){
                    BJUI.alertmsg('ok', json.message);
                }else{
                    BJUI.alertmsg('info', json.message);
                }
            }
        })
    }

</script>